import os

datasets_path   = "dataset/train"
types_tmp      = os.listdir(datasets_path)
types_name      = sorted(types_tmp)

list_file = open('cls_train.txt', 'w')
for cls_id, type_name in enumerate(types_name):
    photos_path = os.path.join(datasets_path, type_name)
    if not os.path.isdir(photos_path):
        continue
    # photos_name=['001.jpg','002.jpg',……]
    photos_name = os.listdir(photos_path)

    for photo_name in photos_name:
        if photo_name.split('.')[-1] == 'jpg':
            # photo_name='001.jpg'
            # cls_id;img_path
            list_file.write(str(cls_id) + ";" + '%s'%(os.path.join(os.path.abspath(datasets_path), type_name, photo_name)))
            list_file.write('\n')
list_file.close()

datasets_path   = "dataset/test"
types_tmp      = os.listdir(datasets_path)
types_name      = sorted(types_tmp)

list_file = open('cls_train.txt', 'a')
for cls_id, type_name in enumerate(types_name):
    photos_path = os.path.join(datasets_path, type_name)
    if not os.path.isdir(photos_path):
        continue
    photos_name = os.listdir(photos_path)

    for photo_name in photos_name:
        if photo_name.split('.')[-1] == 'jpg':
            # photo_name='001.jpg'
            # cls_id;img_path
            list_file.write(str(cls_id) + ";" + '%s'%(os.path.join(os.path.abspath(datasets_path), type_name, photo_name)))
            list_file.write('\n')
list_file.close()